program k;

{$APPTYPE CONSOLE}

type
  TLongInteger = class
    Multiply(b: TLongInteger);
  end;
var
  n, m, i: LongInt;
  x: Extended;
begin
  readln(n, m);

  x := 1;
  for i := 1 to n do
    x := 2 * x;
  Writeln(x - n - 1 mod m:0:0);
end.
